package com.sqpoll.android.settings;

import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.util.Log;

import com.actionbarsherlock.app.SherlockPreferenceActivity;
import com.facebook.Session;
import com.sqpoll.android.R;

/**
 * The activity for settings
 * 
 * @author Honggyun Bae, Younggue Bae
 */
public class SettingsActivity extends SherlockPreferenceActivity {
	private static final String TAG = "SettingsActivity";
	
	private Preference mPrefLogout;
	
  @SuppressWarnings("deprecation")
	@Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      addPreferencesFromResource(R.xml.settings);
      
      mPrefLogout = (Preference) findPreference("pref_key_log_out");
      mPrefLogout.setOnPreferenceClickListener(mPreferenceClickListener);
  }
  
  OnPreferenceClickListener mPreferenceClickListener = new OnPreferenceClickListener() {
		@Override
		public boolean onPreferenceClick(Preference preference) {
			if(preference.getKey().equals("pref_key_log_out")){
				Session session = Session.getActiveSession();
				if (!session.isClosed()) {
					session.closeAndClearTokenInformation();
					
					Log.i(TAG, "log-out!");
				}
			}
			return false;
		}
	};
}
